package com.ambow.shop.action.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ambow.shop.action.Action;
import com.ambow.shop.domain.User;
import com.ambow.shop.service.UserService;
import com.ambow.shop.service.impl.UserServiceImpl;

/**
 * 管理员登出动作。
 * 
 * @author deng.zhao
 *
 */
public class AddAuthorizationAction implements Action {
	private UserService userService = new UserServiceImpl();

	@Override
	public String execute(HttpServletRequest request, HttpServletResponse response) {
		String name = request.getParameter("name");
		String password = request.getParameter("password");

		User user = userService.login(name, password);
		// 验证用户是否为空；
		if (user != null) {	// 若否
			// 登录成功；
			HttpSession session = request.getSession();
			session.setAttribute("user", user);
			return "../view/manage.jsp";
		} else {
			return "./index.jsp";
		}

	}

}
